package com.wkhyapp.lm.contract;

import com.wkhyapp.lm.BuildConfig;
import com.wkhyapp.lm.base.BasePresenter;
import com.wkhyapp.lm.http.ApiCallback;
import com.wkhyapp.lm.http.net.BaseRequest;
import com.wkhyapp.lm.http.net.CheckVersionDto;
import com.wkhyapp.lm.http.net.GoodsListRequest;
import com.wkhyapp.lm.http.net.MemberFollowRequest;
import com.wkhyapp.lm.http.net.SuperResponse;
import com.wkhyapp.lm.http.vo.Category;
import com.wkhyapp.lm.http.vo.Follows;
import com.wkhyapp.lm.http.vo.Goods;
import com.wkhyapp.lm.http.vo.Member;
import com.wkhyapp.lm.utils.MemberUtils;

/**
 * Created by Administrator on 2021-10-2.
 */

public class ShopPresenter extends BasePresenter<ShopView> {


    public ShopPresenter(ShopView shopView) {
        super(shopView);
    }


    public void checkVersion(){
        CheckVersionDto request = new CheckVersionDto();
        request.setVersion(BuildConfig.VERSION_NAME);
        addSubscription(apiStores.checkVersion(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.checkVersion();
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });

    }


    public void  getCategry(int userId){
        BaseRequest request = new BaseRequest();
        request.setUserId(userId);
        addSubscription(apiStores.userCategorys(request),new ApiCallback<SuperResponse<Category>>() {
            @Override
            public void onSuccess(SuperResponse<Category> response) {
                mvpView.setCategoory(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });

    }

    public void getData(int userId,int typeId){
        GoodsListRequest request = new GoodsListRequest();
        request.setUserId(userId);
        request.setTypeId(typeId);
        request.setPageNo(1);
        request.setPageSize(12);
        addSubscription(apiStores.shopGoodsList(request),new ApiCallback<SuperResponse<Goods>>() {
            @Override
            public void onSuccess(SuperResponse<Goods> response) {
                mvpView.setGoods(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
            }
            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });

    }

    public void getDataMore(int pageNo,int userId,int typeId){
        GoodsListRequest request = new GoodsListRequest();
        request.setUserId(userId);
        request.setPageNo(pageNo);
        request.setTypeId(typeId);
        request.setPageSize(12);
        addSubscription(apiStores.shopGoodsList(request),new ApiCallback<SuperResponse<Goods>>() {
            @Override
            public void onSuccess(SuperResponse<Goods> response) {
                mvpView.setGoodsMore(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
            }
            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }


    public void  getShop(int userId){
        BaseRequest request = new BaseRequest();
        request.setUserId(userId);
        if(MemberUtils.isLogin()){
            request.setLoginUserId(MemberUtils.getUid());
        }
        addSubscription(apiStores.shopInfo(request),new ApiCallback<SuperResponse<Member>>() {
            @Override
            public void onSuccess(SuperResponse<Member> response) {
                mvpView.setShop(response.getItem());
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });

    }


    public void  follow(int userId){
        MemberFollowRequest request = new MemberFollowRequest();
        request.setUserId(MemberUtils.getUid());
        request.setFollowUserId(userId);
        addSubscription(apiStores.followMember(request),new ApiCallback<SuperResponse<Follows>>() {
            @Override
            public void onSuccess(SuperResponse<Follows> response) {
                mvpView.setFollows(response.getItem());
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });

    }


    public void  ccopy(int userId){
        BaseRequest request = new BaseRequest();
        request.setUserId(userId);
        addSubscription(apiStores.updateWcharCopy(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.succ();
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });

    }
}
